<?php
require_once 'class/space/Room.php';
require_once 'Action.php';
/**
 * Move class, performs the south,north,east,west,up and down commands
 * @static
 * @package action
 * @author alcaitiff
 */
class Move implements Action
{
	/**
	*	Usage:	south | north | east | west | up | down
    * @static
    * @param Command $command Command
    * @param int $tick Tick
	* @return Room|String This command will try to move the char to the desired direction
    *
	*	If it success a look command will display the new room, otherwise it will display an error message
    **/
	static public function run($command,$tick){
		//Get the char room
        $char=$command->character;
        $direction=$command->command;
		$room=$char->getRoom();
		$dir=$room->getDirectionByName($direction);
		if($dir!=null){
			if($dir instanceof Room){
				return $char->setRoom($dir,$direction,$room); //change room
			}else{
				return $dir;
			}
		}else{
			MessageSystem::addErrorMessage('No exit available to '.$direction);
            return null;
		}
	}
}